/*
将一个整数转为罗马数
输入数在 1 至 3999 之间
I -- 1
V -- 5
X -- 10
L -- 50
C -- 100
D -- 500
M -- 1000
*/
(function(win) {
	function intToRoman(num) {
		var roman = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];
		var numArr = num.toString().split('');
		for (var i = 0; i < numArr.length; i++) {
			var n = Number(numArr[numArr.length - 1 - i]);
			numArr[numArr.length - 1 - i] = '';
			if (n >= 5 && n < 9) {
				numArr[numArr.length - 1 - i] = roman[2 * i + 1];
				for (var j = 0; j < n - 5; j++) {
					numArr[numArr.length - 1 - i] += roman[2 * i];
				}
			} else if (n == 9) {
				numArr[numArr.length - 1 - i] = roman[2 * i] + roman[2 * i + 2];
			} else if (n == 4) {
				numArr[numArr.length - 1 - i] = roman[2 * i] + roman[2 * i + 1];
			} else {
				for (var j = 0; j < n; j++) {
					numArr[numArr.length - 1 - i] += roman[2 * i];
				}
			}
		}
		return numArr.join('');
	}

	console.log(intToRoman(429));
})(window)